home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / tip.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  3KB  |  137 lines

  1. /* "Dumb terminal" session command for serial lines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  *
  4.  *    Feb '91    Bill Simpson
  5.  *        rlsd control and improved dialer
  6.  */
  7.  
  8. /****************************************************************************
  9. *    $Id: tip.c 1.2 93/07/16 11:51:43 ROOT_DOS Exp $
  10. *    14 Jun 93    1.2        GT    Fix warnings.                                    *
  11. *
  12. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  13. *
  14. *      __stdargs tip_out, dotip
  15. *        Include st_asy.h in place of 8250.h
  16. *
  17. ****************************************************************************/
  18.  
  19. #include "config.h"
  20. #include "global.h"
  21. #include "mbuf.h"
  22. #include "proc.h"
  23. #include "iface.h"
  24. #ifdef ATARI
  25. #include "st_asy.h"
  26. #else
  27. #include "8250.h"
  28. #endif
  29. #include "asy.h"
  30. #include "tty.h"
  31. #include "session.h"
  32. #include "socket.h"
  33. #include "commands.h"
  34. #include "devparam.h"
  35. #include "ip.h"
  36.  
  37.  
  38. static void __stdargs tip_out __ARGS((int dev,void *n1,void *n2));
  39.  
  40.  
  41. /* Execute user telnet command */
  42.  
  43. int __stdargs dotip(int argc, char *argv[], void *p)
  44. {
  45.     struct session *sp;
  46.     struct iface *ifp;
  47.     char *ifn;
  48.     int (*rawsave) __ARGS((struct iface *,struct mbuf *));
  49.     int c;
  50.  
  51.     if ((ifp = if_lookup(argv[1])) == NULLIF)  {
  52.         tprintf("Interface %s unknown\n", argv[1]);
  53.         return 1;
  54.     }
  55.  
  56.     if (ifp->dev >= ASY_MAX || Asy[ifp->dev].iface != ifp )  { 
  57.         tprintf("Interface %s not asy port\n", argv[1]);
  58.         return 1;
  59.     }
  60.  
  61.     if (ifp->raw == bitbucket)  {
  62.         tprintf("tip or dialer session already active on %s\n", argv[1]);
  63.         return 1;
  64.     }
  65.  
  66.     /* Allocate a session descriptor */
  67.     
  68.     if ((sp = newsession(argv[1], TIP)) == NULLSESSION)  {
  69.         tprintf("Too many sessions\n");
  70.         return 1;
  71.     }
  72.  
  73.     /* Save output handler and temporarily redirect output to null */
  74.     
  75.     rawsave = ifp->raw;
  76.     ifp->raw = bitbucket;
  77.  
  78.     /* Suspend the packet input driver. Note that the transmit driver
  79.      * is left running since we use it to send buffers to the line.
  80.      */
  81.  
  82.     suspend(ifp->rxproc);
  83.  
  84.     /* Put tty into raw mode */
  85.  
  86.     sp->ttystate.echo = 0;
  87.     sp->ttystate.edit = 0;
  88.     sockmode(sp->output, SOCK_BINARY);
  89.  
  90.     /* Now fork into two paths, one rx, one tx */
  91.     
  92.     ifn = if_name( ifp, " tip out" );
  93.     sp->proc1 = newproc(ifn, 256, tip_out, ifp->dev, NULL, NULL, 0);
  94.     free(ifn);
  95.  
  96.     ifn = if_name(ifp, " tip in" );
  97.     chname(Curproc, ifn );
  98.     free(ifn);
  99.  
  100.     /* bring the line up (just in case) */
  101.     
  102.     if ( ifp->ioctl != NULL )
  103.         (*ifp->ioctl)( ifp, PARAM_UP, TRUE, 0L );
  104.  
  105.     while((c = get_asy(ifp->dev)) != -1)
  106.         tputc(c & 0x7f);
  107.     tflush();
  108.  
  109.     killproc(sp->proc1);
  110.     sp->proc1 = NULLPROC;
  111.     ifp->raw = rawsave;
  112.     resume(ifp->rxproc);
  113.     keywait(NULLCHAR, 1);
  114.     freesession(sp);
  115.     return 0;
  116. }
  117.  
  118.  
  119. /* Output process, DTE version */
  120.  
  121. static void __stdargs tip_out(int dev, void *n1, void *n2)
  122. {
  123.     struct mbuf *bp;
  124.     int c;
  125.  
  126.     while ((c = recvchar(Curproc->input)) != EOF) {
  127.         if (c == '\n')
  128.             c = '\r';                                    /* NL => CR                      */
  129.         bp = pushdown(NULLBUF, 1);
  130.         bp->data[0] = c;
  131.         asy_send(dev, bp);
  132.         Asy[dev].iface->lastsent = secclock();
  133.     }
  134. }
  135.  
  136.  
  137.